<?php 
session_start();

include("Validator.php");
$con=mysql_connect("localhost", "smidpet5", "aez9okai");
// Check connection
if (!$con)
  {
echo "Failed to connect to MySQL: " . mysql_connect_error();
  }
// Create database
mysql_select_db("smidpet5");  		
 $jmeno = mysql_query("SELECT * FROM uzivatele", $con) ; 		
if (!empty($_POST)){
	$pole = array();
while ($current=mysql_fetch_array($jmeno)){
$x=strcmp($current["jmeno"],$_POST['jmeno']);

if($x==0){
   $y=strcmp($current["heslo"],md5($_POST['heslo']));
if($y==0){
  $pole = array();
  $jmeno=$current["jmeno"];
  $Id=$current["id"];           
break;
}
else{
  $pole['heslo'] = 'Neznáme heslo';} 
}
else{
  $pole['jmeno'] = 'Neznámí uživatele';}
}
}   	
if (isset($pole)){
if (!empty($pole)){ 	       
foreach ($pole as $a){
echo "<div>  " . $a . "</div><br/>";
echo "<meta http-equiv='refresh' content='0;url=index.php'>";
} 
}
else{
  $_SESSION=array();   
  $_SESSION['jmeno']=$jmeno;   
  $_SESSION['id'] =$Id;
  $_SESSION['mazani']=true; 
echo"Login:".$_SESSION['jmeno'];
echo "<meta http-equiv='refresh' content='3;url=bmi.php'>";    
}
}
   